#include <iostream>
#include <thread>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
extern int tcp_main();
extern void udp_main();
extern void tcp_exit();
extern void udp_exit();

void signal_handler(int sig, siginfo_t *info, void *context)
{
    udp_exit();
    tcp_exit();

    // 退出程序
    exit(0);
}

int main(int argc, char **argv)
{
    struct sigaction sa;
    sa.sa_sigaction = signal_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_SIGINFO;

    // 设置 SIGINT 信号捕捉函数
    if (sigaction(SIGINT, &sa, NULL) != 0)
    {
        fprintf(stderr, "Could not set signal handler for SIGINT\n");
        return 1;
    }

    std::thread tcp(tcp_main);
    udp_main();

    tcp.join();
    return 0;
}
